package com.gql.functionalInterface;

import org.junit.jupiter.api.Test;

import java.util.function.Consumer;

/**
 * description: 四大核心函数式接口
 *      1.消费型接口Consumer<T>      void accept(T t);
 *      2.供给型接口Supplier<T>      T get();
 *      3.函数型接口Function<T,R>    R apply(T t);
 *      4.断定型接口Predicate<T>     boolean test(T t);
 * @author: gql
 * @date: 2022/04
 */
public class Functional01Test {

    @Test
    public void functionTest() {
        // 1.传统写法
        consumer(500, new Consumer<Double>() {
            @Override
            public void accept(Double aDouble) {
                System.out.println("我有= " + aDouble + "元.");
            }
        });

        // 2.函数式接口
        consumer(600, money -> System.out.println("我有= " + money + "元."));
    }

    public void consumer(double money, Consumer<Double> con) {
        con.accept(money);
    }
}
